package com.colin.springbootsource.initializer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Colin
 * 2019/12/21 15:57
 * @desc todo
 * @email zhaod@oceansoft.com.cn
 */
@Slf4j
@Order(3)
public class ThirdInitializer implements ApplicationContextInitializer {
    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        Map<String, Object> map = new HashMap<>(6);
        map.put("key3", "value3");
        MapPropertySource firstInitializer = new MapPropertySource("thirdInitializer", map);
        environment.getPropertySources().addLast(firstInitializer);
        if (log.isInfoEnabled()){
            log.info("Run ThirdInitializer");
        }
    }
}
